package org.water.common.content;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ContextLoader;

/**
 * 服务启动完成之后才可以访问
 * @author qzy
 *
 */
@Component
public class SpringContentUtil implements ApplicationContextAware {

	private static ApplicationContext applicationContext;
	
	public SpringContentUtil() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void setApplicationContext(ApplicationContext cotent) throws BeansException {
		// TODO Auto-generated method stub
		applicationContext=cotent;
	}

	public static ApplicationContext getApplicationContext()
	{
		return applicationContext;
	}
	/**
	 * 根据名称获取
	 * @param beanName
	 * @return
	 */
	public static Object getBean(String beanName)
	{
		Object bean=null;
		if(applicationContext!=null)
		{
			bean=applicationContext.getBean(beanName);
		}
		return bean;
	}
	/**
	 * 
	 * @param class1
	 * @return
	 */
	public static Object getBean(Class<?> class1)
	{
		Object bean=null;
		if(applicationContext!=null)
		{
			bean=applicationContext.getBean(class1);
		}
		return bean;
	}
}
